<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim" id="website-expertCheck" lay-title="专家审查举报管理"
     xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="expertCheck-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-expertCheck">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">课题名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input"
                                                   placeholder="请输入课题名称">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">主持人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="leaderName" autocomplete="off" class="layui-input"
                                                   placeholder="请输入主持人">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学科分类</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="expertCheck : ${subjectType}"
                                                        th:value="${expertCheck.code}" th:text="${expertCheck.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="expertCheckTable" lay-data="{id: 'expertCheckTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--表格中字典的显示-->
<script type="text/html" id="levelType">
    {{#
    var dict=layui.dict.getByCode(d.levelTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  }else { }}
    <span>未定级</span>
    {{#  } }}
</script>

<!--表格中的操作栏-->
<script type="text/html" id="expertCheck-option">
    <a lay-event="detail" class="website-blue">详情</a>
    {{# if(d.report.isExpertReal===null ){}}
    <a lay-event="real" class="website-green">属实</a>
    <a lay-event="noReal" class="website-blue">不属实</a>
    {{#  } }}
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'website', 'dict'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            dict = layui.dict,
            dropdown = layui.dropdown,
            $view = $('#website-expertCheck'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;
        form.render();
        initTable();

        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(expertCheckTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                website.modal.view('详情', 'biz/report/expertCheckDetail/' + data.report.reportId, {
                    area: $(window).width() <= 750 ? '95%' : '50%'
                });
            }
            if (layEvent === 'real') {
                website.modal.confirm('确定信息', '确定标记该举报信息属实？', function () {
                    website.post(ctx + 'biz/report/update/' + data.report.reportId, {isExpertReal: true}, function () {
                        layer.closeAll();
                        website.alert.success('标记完成');
                        $('#website-expertCheck').find('#query').click();
                    });
                });
            }
            if (layEvent === 'noReal') {
                layer.open({
                    type: 1
                    , title: '不属实原因' //不显示标题栏
                    , shade: 0.4
                    , area: $(window).width() <= 750 ? '80%' : '40%'
                    , id: 'LAY_layuinoreal' //设定一个id，防止重复弹出
                    , btn: ['提交', '关闭']
                    , btnAlign: 'c'
                    , zIndex: layer.zIndex
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div class="layui-row" style="margin-top: 20px; margin-right: 20px;">' +
                        '                <div class="layui-col-md12">' +
                        '                    <label class="layui-form-label">不属实原因：</label>' +
                        '                    <div class="layui-input-block">' +
                        '                        <textarea id="checkResult" placeholder="请输入不属实原因" class="layui-textarea"' +
                        '                                  rows="3"></textarea>' +
                        '                    </div>' +
                        '                </div>' +
                        '            </div>'
                    , yes: function (index, layero) {
                        var checkResult = layero.find('#checkResult').val();
                        if (!checkResult) {
                            website.alert.error('请输入不属实原因');
                            return false;
                        }
                        website.post(ctx + 'biz/report/update/' + data.report.reportId, {
                            isExpertReal: false,
                            expertReason: checkResult
                        }, function () {
                            layer.closeAll();
                            website.alert.success('标记完成');
                            $('#website-expertCheck').find('#query').click();
                        });
                    }
                });
            }
        });

        /**
         * 表格的排序点击
         **/
        table.on('sort(expertCheckTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });


        /**
         * 初始化表格
         */
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'expertCheckTable',
                url: ctx + 'biz/report/expert/list',
                cols: [[
                    /*{type: 'checkbox'},*/
                    {type: 'numbers', title: '序号'},
                    {field: 'name', title: '课题名称', minWidth: 100},
                    {
                        title: '选题名称', minWidth: 100, templet: function (d) {
                            return d.topic.topicName;
                        }
                    },
                    {field: 'topicCode', title: '指南序号', minWidth: 100},
                    {field: 'leaderName', title: '主持人', minWidth: 100},
                    {title: '定级', templet: '#levelType', minWidth: 100},
                    {title: '操作', toolbar: '#expertCheck-option', minWidth: 200}
                ]]
            });
        }

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            return params;
        }
    })
</script>